package com.chb.controller;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.net.URI;

/**
 * @author: 陈海彬
 * @date: Created in 2023/9/25 15:59
 * @description: 视图跳转控制器————进行页面跳转
 * @modified By:
 * @version: 1.0
 */
@Controller
@RequestMapping("/view/*")
public class ViewController {

    /**
     * @param request 获取请求的url
     * @create by: 陈海彬
     * @description: 对路径进行统一跳转
     * @create time: 2023/9/25 19:59
     */
    @RequestMapping
    public String toMain(HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        //判断是否是主页面
        if (requestURI.contains("index")) {
            return "index";
        }

        String[] parts = requestURI.split("/");
        //获取分割后的第三个部分(下标为2)
        String toXXX = parts[2].substring(2);
        //将第一个字母变为小写
        String result = toXXX.substring(0, 1).toLowerCase() + toXXX.substring(1);
        return result;
    }
}





